<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>后端注册界面</title>
		<link rel="stylesheet" href="css/bootstrap.css" />
		<link rel="stylesheet" href="css/register.css" />
		<script src="node_modules/axios/dist/axios.js"></script>
	</head>
	<body>
		<div class="container">
			<h2>D+</h2>
			<p>创建一个D+新账户</p>
			<form id="login">
				<input type="text" id="nickname" placeholder="请输入昵称" />
				<input type="text" id="phone" placeholder="请输入手机号" required />
				<input type="text" id="email" placeholder="请输入邮箱" required />
				<input type="password" id="password" required placeholder="请输入密码" />
				<input type="password" id="password2" required placeholder="请确认密码" />
				<div class="gender_f">
					<p>性别：</p>
					<div><input type="radio" name="gender" class="gender" value="1" />男</div>
					<div><input type="radio" name="gender" class="gender" value="0" />女</div>
				</div>
				<div class="form-group col-sm-12 role_sel">
					<select class="form-control" id="sel">
						身份
					</select>
				</div>
				<input type="file" id="file" />
				<label for="" class="head_text">选择头像:</label>
				<button type="button" class="head_img">+</button>
				<input type="submit" id="sub" value="注册" />
			</form>

			<div class="forget">
				<a href="javascript:void(0)"> 忘记密码了?</a>
				<a href="login.html">返回登录</a>
			</div>
		</div>
	</body>
	<script src="js/register.js"></script>
	<script>
		let admin = new Admin();
		//判断是否有权限
		// admin.jurisdiction();
		let formdata = new FormData();

		admin.createOption("https://ty.php800.cn/api/member/role.php", "#sel", "rolename");

		document.querySelector("#sel").addEventListener("change", function () {
			formdata.append("roleid", this.value);
		});

		document.querySelectorAll(".gender").forEach((item) => {
			item.addEventListener("click", () => {
				formdata.append("gender", item.value);
			});
		});
		document.querySelector(".head_img").addEventListener("click", () => {
			admin.heade("#file", (res) => {
				formdata.append("useravatar", res);
			});
		});

		document.querySelector("#login").addEventListener("submit", function (e) {
			e.preventDefault();
			formdata.append("nickname", document.querySelector("#nickname").value);
			formdata.append("phone", document.querySelector("#phone").value);
			formdata.append("email", document.querySelector("#email").value);
			formdata.append("password", document.querySelector("#password").value);
			formdata.append("password2", document.querySelector("#password2").value);

			admin
				.register("https://ty.php800.cn/api/member/userregister.php", formdata)
				.then((result) => {})
				.catch((err) => console.log(err));
		});
	</script>
</html>
